#include <std.h>

#include <memory.h>

/*Data type registry*/

#define MAX_DT 10
#define DT_NAME_LEN 32

/*This is the data type descriptor table. It maps the type to the name of the datatype.*/
struct dt_desctable	{
	char name[DT_NAME_LEN];
}dt_desctable[MAX_DT];

struct dt_list	{
	int type;	/*The type that this node holds. This is the index into the array dt_reg[]*/
	struct dt_list *next;
};

struct dt_reg	{
	unsigned size;	/*Total size occupied by this data type*/
	struct dt_list *dt_list; /*If this is null then this is a primitive data type, otherwise points to a list of types that are members of this type*/
}dt_reg[MAX_DT];


void register_primitive(int type,unsigned size,char *name)
{
	dt_reg[type].size=size;
	dt_reg[type].dt_list=NULL; /*This is a primitive data type, hence has no members*/
	strcpy(dt_desctable[type].name,name);
}

void init_dt_reg()
{
	memset(dt_reg,NULL,MAX_DT*sizeof(struct dt_reg));
	memset(dt_desctable,NULL,MAX_DT*sizeof(struct dt_desctable));
	register_primitive(0,1,"char");
	register_primitive(1,2,"short");
	register_primitive(2,4,"long");
}

/*OS display functions*/

void list_dt_reg()
{
	int i;
	printk("\nRegistered datatypes:");
	for(i=NULL;i<MAX_DT && dt_reg[i].size;i++)	{
		printk("\n%d:%s size:%d",i,dt_desctable[i].name,dt_reg[i].size);
	}
}
